package com.ye.zcswzlms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ye.zcswzlms.entity.Users;
import com.ye.zcswzlms.mapper.UsersMapper;
import com.ye.zcswzlms.service.IUsersService;
import com.ye.zcswzlms.utils.SaltGenarator;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends ServiceImpl<UsersMapper, Users> implements IUsersService {
    @Autowired
    private UsersMapper userMapper;
    @Override
    public void register(Users users) {
        String salt = SaltGenarator.getSalt(8);
        users.setPasswordSalt(salt);
        Md5Hash md5Hash = new Md5Hash(users.getPassword(), salt, 1024);
        users.setPassword(md5Hash.toHex());

        save(users);
    }

    @Override
    public Users getUsers(String stuNo) {

        Users userBystuNo = userMapper.getByStuNo(stuNo);
        return userBystuNo;
    }
}
